package com.zhonghui.procurement.service.Impl;

import com.zhonghui.common.utils.SecurityUtils;
import com.zhonghui.procurement.domain.ProcurementPushUser;
import com.zhonghui.procurement.domain.vo.ProcurementPushUserVo;
import com.zhonghui.procurement.mapper.ProcurementPushUserMapper;
import com.zhonghui.procurement.service.IProcurementPushUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProcurementPushUserServiceImpl implements IProcurementPushUserService {
    @Autowired
    private ProcurementPushUserMapper procurementPushUserMapper;

    @Override
    public List<ProcurementPushUserVo> selectProcurementPushUserList(ProcurementPushUser procurementPushUser) {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        procurementPushUser.setUserId(userId);
        return procurementPushUserMapper.selectProcurementPushUserList(procurementPushUser);
    }

    @Override
    public String updateStatus(Integer listId) {
        Integer id = procurementPushUserMapper.getPushId(listId);
        Long userId = SecurityUtils.getLoginUser().getUserId();


        if(id != null){
            Integer integer = procurementPushUserMapper.ifExist(id, Math.toIntExact(userId));
            if(integer != null){
                procurementPushUserMapper.updateStatus(id, Math.toIntExact(userId));
                return "操作成功";
            }

        }
        return "数据异常,请稍后再试";
    }
}
